package com.example.zzm.yuejian03.Model;

import com.example.zzm.yuejian03.Bean.CollectclubBean;
import com.example.zzm.yuejian03.Iface.ClubcollectIface;
import com.example.zzm.yuejian03.Listener.ClubcollectListrener;
import com.example.zzm.yuejian03.Server;
import com.example.zzm.yuejian03.Service.Service;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class ClubcollectModel implements ClubcollectIface {

    private Retrofit retrofit;

    public ClubcollectModel(){
        retrofit = new Retrofit.Builder()
                .baseUrl(Server.BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    @Override
    public void getClubcollectList(int user_id,final ClubcollectListrener listener) {
        Service service
                =retrofit.create(Service.class);
        Call<List<CollectclubBean>> call
                =service.getClubcollectList(user_id);


        call.enqueue(new Callback<List<CollectclubBean>>() {
            @Override
            public void onResponse(Call<List<CollectclubBean>> call, Response<List<CollectclubBean>> response) {
                if(response.isSuccessful() && response!=null)
                {  listener.onResponse(response.body());
                }
                else   listener.onFail("on response fail");
            }
            @Override
            public void onFailure(Call<List<CollectclubBean>> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });

    }
}
